<template>
	<view class="pl10 pr10 d-flex a-center flex-wrap">
		<view class="mb15 width-50 pl5 pr5 boxSizing" v-for="(item,index) in classroomCount" :key="index">
			<view class="w100p">
				<view class="content_item p10 boxSizing">
					<view class="itemName d-flex a-center">
						<view class="point mr5"></view>
						<view class="fs14">{{classroomData[index]}}</view>
					</view>
					<view class="d-flex a-center j-sb mt15 mb10">
						<view class="height28p w100p itemBoxPadding2 mr10 bdr4"
							:class="classroomDataBgColor[classroomDataStatus[index].socketColor]">
							<view class="w100p h100p d-flex a-center">
								<view class="d-flex-center mr5">
									<u--image src="/static/img/feature/children/white_lamp.png" width="40rpx" height="40rpx"></u--image>
								</view>
								<view class="flex-1 d-flex-center fs14">
									<view class="mr5 white">
										{{item.deviceValue}}
									</view>
									<view class="unit fs12">A</view>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>
<script>
	import {
		queryOneListWorkingByAppNumV2,
		queryOneListWorkingByAppStatusV2
	} from "@/api/dormBuilding/oneBuildOneFloor.js"

	export default {
		data() {
			return {
				timeout: [],

				classroomData: ['1101-1106室', '1107-1112室', '1114室', '1115室', '宿管间'],
				classroomCount: [],

				classroomDataStatus: [],

				classroomDataBgColor: ['bgColor_info', 'bgColor_success', 'bgColor_danger', 'bgColor_blue',
					'bgColor_warning', 'bgColor_red', 'bgColor_orange'
				],
				classroomDataBorder: ['border_info', 'border_success', 'border_danger', 'border_blue',
					'border_warning', 'border_red', 'border_orange'
				],
				classroomDataFontColor: ['font_info', 'font_success', 'font_danger', 'font_blue',
					'font_warning', 'font_red', 'font_orange'
				],
			}
		},
		mounted() {
			this.queryOneListWorkingByAppNumV2()
			this.queryOneListWorkingByAppStatusV2()

			this.setupTimer()
		},
		methods: {
			// 设置定时器
			setupTimer() {
				let _this = this;
				_this.timeout[0] = setInterval(() => {
					_this.queryOneListWorkingByAppNumV2()
				}, 15000);
				_this.timeout[1] = setInterval(() => {
					_this.queryOneListWorkingByAppStatusV2()
				}, 30000);
			},
			// 清除定时器
			clearTimer() {
				let _this = this;
				if (_this.timeout.length > 0) {
					_this.timeout.forEach(item => {
						clearInterval(item);
					})
				}
			},
			async queryOneListWorkingByAppNumV2() {
				await queryOneListWorkingByAppNumV2().then(res => {
					let tempData = res.object || []
					this.classroomCount = tempData
				})
			},
			async queryOneListWorkingByAppStatusV2() {
				await queryOneListWorkingByAppStatusV2().then(res => {
					let tempData = res.object || []
					this.classroomDataStatus = tempData
				})
			}
		},
	}
</script>
<style lang="scss" scoped>
	@import url("@/static/css/operationData.css");
</style>